unit con_NotaVendaSerie;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Formulario_Padrao_Consulta, StdCtrls, Buttons, ExtCtrls, Grids, DBGrids,dbtables,db,
  Mask, ToolEdit;

type
  TFrmConNotaVendaSerie = class(TFrmConsulta)
    DbgNotaVenda: TDBGrid;
    Label1: TLabel;
    EdtData_inicial: TDateEdit;
    procedure EdtNumNotaKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure BtnFecharClick(Sender: TObject);
    procedure EdtData_inicialKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
  public
    { Public declarations }
    nota    :string;
    serie   :string;
    entidade:string;
    procedure Fazconsulta;

  end;

var
  FrmConNotaVendaSerie: TFrmConNotaVendaSerie;

implementation

uses clsNotaVenda,dm, clsBackupVenda;

var
   NotaVenda  :TNotaVenda;
   BackupVenda:TBackupVenda;
   Tq         :TQuery;
   Tds        :TDataSource;
{$R *.DFM}

procedure TFrmConNotaVendaSerie.EdtNumNotaKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
  if key=12 then
    FazConsulta;
end;

procedure TFrmConNotaVendaSerie.Fazconsulta;
begin
  tq.close;
  backupvenda.consultarNotaSerieEnt(entidade,serie,EdtData_inicial.Date,Tq);
  tq.open;
  DbgNotaVenda.DataSource:= tds;
  DbgNotaVenda.Refresh;
end;

procedure TFrmConNotaVendaSerie.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  NotaVenda.free;
  BackupVenda.free;
end;

procedure TFrmConNotaVendaSerie.FormCreate(Sender: TObject);
begin
  inherited;
  NotaVenda   := TNotaVenda.create;
  BackupVenda := TBackupVenda.create;
end;

procedure TFrmConNotaVendaSerie.FormActivate(Sender: TObject);
begin
  inherited;
  tq              :=TQuery.create(DmInt.Db);
  tq.DatabaseName := DmInt.Db.DatabaseName;
  tq.Active       := false;
  tds            := TDataSource.create(self);
  Tds.DataSet    := tq;
  fazconsulta;
end;

procedure TFrmConNotaVendaSerie.BtnFecharClick(Sender: TObject);
begin
  inherited;
  serie   := tq.fieldbyname('bkp_serie').AsString;
  nota    := tq.fieldbyname('bkp_numero').AsString;
  entidade:= tq.fieldbyname('ent_codigo').AsString;
end;

procedure TFrmConNotaVendaSerie.EdtData_inicialKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
  if key=12 then begin
    FazConsulta;
    EdtData_inicial.setfocus;
  end;
end;

end.
